package wnhz.com.business.groupshop.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import wnhz.com.business.R;
import wnhz.com.business.groupshop.bean.OrderBean;

/**
 * Created by Administrator on 2017-07-19.
 */

public class FragmentOneItemAdapter extends BaseAdapter{
    static final String TAG = "FragmentOneItemAdapter";

    private List<OrderBean.InfoBean.GoodsBean> data;
    private LayoutInflater layoutInflater;
    private Context context;

    public FragmentOneItemAdapter(Context context, List<OrderBean.InfoBean.GoodsBean> data) {
        this.context = context;
        this.data = data;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new FragmentOneItemAdapter.ViewHolder();
            // 获取组件布局
            convertView = layoutInflater.inflate(R.layout.item_main_two_item_layout, null);
            holder.iv_img = (ImageView) convertView.findViewById(R.id.iv_img);
            holder.tv_newprice = (TextView) convertView.findViewById(R.id.tv_newprice);
            holder.tv_oldprice = (TextView) convertView.findViewById(R.id.tv_oldprice);
            holder.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
            holder.tv_buy = (TextView) convertView.findViewById(R.id.tv_buy);
            holder.tv_num = (TextView) convertView.findViewById(R.id.tv_num);
            holder.item_layout = (LinearLayout) convertView.findViewById(R.id.item_layout);
            // 这里要注意，是使用的tag来存储数据的。
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        //中间加横线
        holder.tv_oldprice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);


        Glide.with(context).load("http://pic2.ooopic.com/13/60/34/41b1OOOPICa4.jpg").into(holder.iv_img);

//        holder.item_layout.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                LogUtils.e("----------99-","-------99---"+data.get(position).goodsId);
//                context.startActivity(RebateGoodsDetailsActivity.createIntent(context, data.get(position).goodsId, data.get(position).img, "5"));
//            }
//        });
        return convertView;
    }

    public class ViewHolder {
        public TextView tv_title;
        public TextView tv_newprice;
        public TextView tv_oldprice;
        public TextView tv_buy;
        public TextView tv_num;
        public ImageView iv_img;
        public LinearLayout item_layout;
    }
}
